//! Events related to actor supervision

use std::fmt::{Debug, Display};
use crate::actor::PID;

/// Supervision event stream for broadcasting supervision events
pub struct SupervisionEventStream;

/// Event sent when an actor is started
#[derive(Clone, Debug)]
pub struct ActorStartedEvent {
    /// PID of the actor
    pub pid: PID,
}

/// Event sent when an actor is stopping
#[derive(Clone, Debug)]
pub struct ActorStoppingEvent {
    /// PID of the actor
    pub pid: PID,
}

/// Event sent when an actor is stopped
#[derive(Clone, Debug)]
pub struct ActorStoppedEvent {
    /// PID of the actor
    pub pid: PID,
}

/// Event sent when an actor has failed
#[derive(Clone, Debug)]
pub struct ActorFailedEvent {
    /// PID of the actor
    pub pid: PID,
    /// The error that caused the failure
    pub reason: String,
    /// Whether the actor will be restarted
    pub restart: bool,
}

/// Event sent when an actor is restarted after failure
#[derive(Clone, Debug)]
pub struct ActorRestartedEvent {
    /// PID of the actor
    pub pid: PID,
    /// The error that caused the restart
    pub reason: String,
}

impl SupervisionEventStream {
    /// Publish an event that an actor has started
    pub fn publish_started(pid: &PID) {
        // In a real implementation, this would publish to an event stream
        let event = ActorStartedEvent {
            pid: pid.clone(),
        };
        println!("Actor started: {}", pid);
    }
    
    /// Publish an event that an actor is stopping
    pub fn publish_stopping(pid: &PID) {
        // In a real implementation, this would publish to an event stream
        let event = ActorStoppingEvent {
            pid: pid.clone(),
        };
        println!("Actor stopping: {}", pid);
    }
    
    /// Publish an event that an actor has stopped
    pub fn publish_stopped(pid: &PID) {
        // In a real implementation, this would publish to an event stream
        let event = ActorStoppedEvent {
            pid: pid.clone(),
        };
        println!("Actor stopped: {}", pid);
    }
    
    /// Publish an event that an actor has failed
    pub fn publish_failed(pid: &PID, reason: &str, restart: bool) {
        // In a real implementation, this would publish to an event stream
        let event = ActorFailedEvent {
            pid: pid.clone(),
            reason: reason.to_string(),
            restart,
        };
        println!("Actor failed: {} with reason: {}, restart: {}", pid, reason, restart);
    }
    
    /// Publish an event that an actor has been restarted
    pub fn publish_restarted(pid: &PID, reason: &str) {
        // In a real implementation, this would publish to an event stream
        let event = ActorRestartedEvent {
            pid: pid.clone(),
            reason: reason.to_string(),
        };
        println!("Actor restarted: {} with reason: {}", pid, reason);
    }
} 